//package java_encrypt;
//
//import org.apache.commons.codec.binary.Base64;
//import sun.misc.BASE64Decoder;
//
//import javax.crypto.Cipher;
//import java.security.KeyFactory;
//import java.security.PrivateKey;
//import java.security.PublicKey;
//import java.security.spec.PKCS8EncodedKeySpec;
//import java.security.spec.X509EncodedKeySpec;
//
//public class demo_06_RSA_do {
////    static String publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCP3wZ9QeuGM/9UnwGULzfxKXhYP/PX5MPAyEiNDmHCQAi+DSqpd1+z5LuHdKkU3qGqCkgwGaOnMGf4LeS/GoUm1HuI4QWJdNUOMAW1VsKM4qotmpzXWuXG/ed9k+Hg3WW0HI9wvbCZsJ9H6XkrFxipf26qTkVnUM+9+47lMy+ybwIDAQAB";
////    static String privateKey = "MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAI/fBn1B64Yz/1SfAZQvN/EpeFg/89fkw8DISI0OYcJACL4NKql3X7Pku4d0qRTeoaoKSDAZo6cwZ/gt5L8ahSbUe4jhBYl01Q4wBbVWwoziqi2anNda5cb9532T4eDdZbQcj3C9sJmwn0fpeSsXGKl/bqpORWdQz737juUzL7JvAgMBAAECgYBjhkze6XMca2v+BeD5uZBha+asZdExUDd6bRKDQaeu0M07a7BPexzhPSHdGn68ySXckzBM1e+4AGxr6pOK/7WLkyqZ95ZZobCQVN71QxW6/EA+ZNdYUR/+6vAqktXZBio0RDBVG1HAKTRWphYT4357KNSg27EEZqmiWbnMHWTtgQJBANsB+meG/M4BIJfmgwk1XECIcmrxG2LDevToc/AGosJUJ/VpWSFLGrmwNMlcqEXk41Z7M6hRWnSL2DQJvPW1JhkCQQCoLBmB2YXI94N+1BsG4f37d6MI4Rm/WUX3HNI9ceuvoIJE2OIDoAWFS9zQFPSxBm1aJYGrOmKltNOOK9DJyF3HAkBe3z6ANoOxId/iraK6DHmIIxOdrBC2+gN7sG743YcIM7iToS1RNN3A7soPKKpkjMDGp9w63/MVZbck48sNjYmRAkB1J1uRmM5ZZQwm024MimzbvMlHy0Cbi35xGpPfmDf+/ksh2RECQ3z1Ehc+ogqgNAED1rMRbLgCBgmGtkFaAIpLAkBreHUxIOWPDXNM9Jg4ROo2AtXsCDHONASJEVYA2ngoYPGfYbX+QwEqBm1mtc0XtU9K4crdNIvakAWuo7VLQ3Cd";
//    static String publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCP3wZ9QeuGM/9UnwGULzfxKXhYP/PX5MPAyEiNDmHCQAi+DSqpd1+z5LuHdKkU3qGqCkgwGaOnMGf4LeS/GoUm1HuI4QWJdNUOMAW1VsKM4qotmpzXWuXG/ed9k+Hg3WW0HI9wvbCZsJ9H6XkrFxipf26qTkVnUM+9+47lMy+ybwIDAQAB";
//    static String privateKey = "MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAI/fBn1B64Yz/1SfAZQvN/EpeFg/89fkw8DISI0OYcJACL4NKql3X7Pku4d0qRTeoaoKSDAZo6cwZ/gt5L8ahSbUe4jhBYl01Q4wBbVWwoziqi2anNda5cb9532T4eDdZbQcj3C9sJmwn0fpeSsXGKl/bqpORWdQz737juUzL7JvAgMBAAECgYBjhkze6XMca2v+BeD5uZBha+asZdExUDd6bRKDQaeu0M07a7BPexzhPSHdGn68ySXckzBM1e+4AGxr6pOK/7WLkyqZ95ZZobCQVN71QxW6/EA+ZNdYUR/+6vAqktXZBio0RDBVG1HAKTRWphYT4357KNSg27EEZqmiWbnMHWTtgQJBANsB+meG/M4BIJfmgwk1XECIcmrxG2LDevToc/AGosJUJ/VpWSFLGrmwNMlcqEXk41Z7M6hRWnSL2DQJvPW1JhkCQQCoLBmB2YXI94N+1BsG4f37d6MI4Rm/WUX3HNI9ceuvoIJE2OIDoAWFS9zQFPSxBm1aJYGrOmKltNOOK9DJyF3HAkBe3z6ANoOxId/iraK6DHmIIxOdrBC2+gN7sG743YcIM7iToS1RNN3A7soPKKpkjMDGp9w63/MVZbck48sNjYmRAkB1J1uRmM5ZZQwm024MimzbvMlHy0Cbi35xGpPfmDf+/ksh2RECQ3z1Ehc+ogqgNAED1rMRbLgCBgmGtkFaAIpLAkBreHUxIOWPDXNM9Jg4ROo2AtXsCDHONASJEVYA2ngoYPGfYbX+QwEqBm1mtc0XtU9K4crdNIvakAWuo7VLQ3Cd";
//    static String data = "15908085458";
//
//    public static void main(String[] args) throws Exception {
//
//        //公钥加密
//        byte[] encryptedBytes=encrypt(data.getBytes(), publicKey);
//        String encryp_data = new String(Base64.encodeBase64URLSafe(encryptedBytes));
//        System.out.println("加密后："+ encryp_data);
//
//        //私钥解密
//        byte[] decryptedBytes=decrypt(Base64.decodeBase64(encryp_data), privateKey);
//        System.out.println("解密后："+new String(decryptedBytes));
//    }
//
//    //公钥加密
//    public static byte[] encrypt(byte[] content, String key) throws Exception{
//        X509EncodedKeySpec keySpec = new X509EncodedKeySpec(new BASE64Decoder().decodeBuffer(key));
//        KeyFactory keyFactory = KeyFactory.getInstance("RSA");
//        PublicKey publicKey = keyFactory.generatePublic(keySpec);
//
//        Cipher cipher= Cipher.getInstance("RSA");
//        cipher.init(Cipher.ENCRYPT_MODE, publicKey);
//        return cipher.doFinal(content);
//    }
//
//    //私钥解密
//    public static byte[] decrypt(byte[] content, String key) throws Exception{
//        PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(new BASE64Decoder().decodeBuffer(key));
//        KeyFactory keyFactory = KeyFactory.getInstance("RSA");
//        PrivateKey privateKey = keyFactory.generatePrivate(keySpec);
//
//        Cipher cipher=Cipher.getInstance("RSA");
//        cipher.init(Cipher.DECRYPT_MODE, privateKey);
//        return cipher.doFinal(content);
//    }
//}
